<?php
	require(dirname(__FILE__).'/includes/client.php');
    $conn = mysql_connect("localhost","root","");
	$client = new client();
    mysql_select_db("send");
    $ip = $client->get_user_ip();
	$brownserType = $client->get_user_agent();
	$brownserLanguage = $client->get_user_lang();
	$userOs = $client->get_user_os();
    $timeStamp = time();
if (isset($_REQUEST['m'])) {
	$m = $_REQUEST["m"];
	$mStr = base64_decode($m);
	$mArr = explode("|", $mStr);
	$mArr[0] = urldecode($mArr[0]);
	$mArr[1] = trim($mArr[1]);
	$mArr[2] = trim($mArr[2]);
	$mArr[3] = is_numeric($mArr[3])?trim($mArr[3]):1;
//	$browserNumSql = "update template set brownserNum = brownserNum + 1 where id = ".$mArr[3]."";
	$browserNumSql = "INSERT INTO template(id,brownserNum) VALUES ($mArr[3],1) ON DUPLICATE KEY UPDATE brownserNum = brownserNum + 1";
	mysql_query($browserNumSql,$conn);
	$sql = "insert into openStatistics(address, addressId, ip, type, timeStamps, templateId, brownserType, brownserLanguage, os) values('".$mArr[0]."',".$mArr[1].",'".$ip."',".$mArr[2].",".$timeStamp.",".$mArr[3].",'".$brownserType."','".$brownserLanguage."','".$userOs."')";

    mysql_query($sql,$conn);
}

DisplayImage();
function DisplayImage()
{
	// open the file in a binary mode
	$name = 'images/track.gif';
	$fp = fopen($name, 'rb');

	// send the right headers
	header("Content-Type: image/gif");
	header("charset=utf-8");
	header("Content-Length: " . filesize($name));
	// dump the picture and stop the script
	//echo "adf";exit;
	fpassthru($fp);
	exit(0);
}
?>